#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

class Solution
{
public:
    int myAtoi(string s)
    {
        int len = s.size(),index=-1;
        long long x=0;
        bool positive = true;
        bool front_zero = true;
        while(index++ < len){
            if(s[index] == '-'){
                positive = false;
                front_zero = true;
                x = 0;
            }
            else if(s[index] == '+'){
                positive = true;
                front_zero = true;
                x = 0;
            }
            else if(front_zero && s[index]=='0'){
                continue;
            }
            else if(front_zero && s[index] > '0' && s[index]<= '9'){
                front_zero = false;
                x = 10 * x + (s[index]-'0');
            }
            else if(front_zero && s[index]!=' ' && (s[index]>='9' || s[index]<='0'))
                return 0;
            else if(!front_zero && s[index] > '0' && s[index]<= '9'){
                x = 10 * x + (s[index]-'0');
            }
            else if(s[index]=='.'){
                index = len;
            }
        }
        x = positive ? x : -1*x;
        if(x>INT_MAX)
            return INT_MAX;
        else if(x < INT_MIN)
            return INT_MIN;
        else
            return x;
    }
};

int main()
{
    Solution solution;
    solution.myAtoi("-91283472332");
    cout << solution.myAtoi("words and 987");
    return 0;
}